
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import org.apache.commons.daemon.Daemon;
import org.apache.commons.daemon.DaemonContext;
import org.apache.log4j.Logger;

import org.sopt.dev.ImgKnight.frontier.Frontier;

public class FrontierWrapper implements Daemon {

	Frontier frontier = Frontier.getInstance();
	
	Logger exceptionLogger = Logger.getLogger("frontier.exception");
	
	public static SimpleDateFormat df = new SimpleDateFormat("[E MMM dd HH:mm:ss]", Locale.UK);
	
	@Override
	public void init(DaemonContext arg0) throws Exception {
		try {
			frontier.init(false);
		} catch (Exception e) {
			System.err.println(e);
			throw e;
		}
		System.out.println(df.format(new Date())+" frontier init\t[OK]");
	}

	@Override
	public void start() throws Exception {
		try {
			frontier.run();
		} catch (Exception e) {
			System.err.println(e);
			throw e;
		}
		System.out.println(df.format(new Date())+" frontier start\t[OK]");
	}
	
	@Override
	public void stop() throws Exception {
		try {
			frontier.shutdown(Frontier.SHUTDOWN);
		} catch (Exception e) {
			System.err.println(e);
			throw e;
		}
		System.out.println(df.format(new Date())+" frontier stop\t[OK]");
	}
	
	@Override
	public void destroy() {
		/* empty */
	}
	
}